package com.xyzk.diagnose.view;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class CToast {
	private static Context context = TApplication.getContext();
	private static Toast toast;

	/**
	 * @param content 显示内容,显示时间短
	 */
	public static void show(String content){
		show(content, Toast.LENGTH_SHORT);
	}

	/**
	 * @param resId 资源id,显示时间短
	 */
	public static void show(int resId){
		show(context.getString(resId), Toast.LENGTH_SHORT);
	}

	/**
	 * @param content 显示内容,显示时间长
	 */
	public static void showLong(String content){
		show(content, Toast.LENGTH_LONG);
	}

	/**
	 * @param resId 资源id，显示时间长
	 */
	public static void showLong(int resId){
		show(context.getString(resId), Toast.LENGTH_LONG);
	}

	/**
	 * @param content 显示内容
	 * @param time    显示时间长短
	 */
	@SuppressLint("InflateParams")
	private static void show(String content,int time){
		View view = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
		TextView tvContent = (TextView) view.findViewById(R.id.tv_toast_content);
		tvContent.setText(content);
		if(toast == null){//解决多次点击,Toast会延迟地不断地出现
			toast = new Toast(context);
		}
		toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 50);
		toast.setDuration(time);
		toast.setView(view);
		toast.show();
	}
}
